package com.bwie.controller;

import com.bwie.pojo.TbType;
import com.bwie.service.TbTypeService;
import com.bwie.utils.R;
import com.bwie.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.TooManyListenersException;

/**
 * @description :
 * @Author QiHainan
 * @Create 2025/5/24 10:22
 * @Version 1.0
 */
@RestController
@RequestMapping("/prod/type")
public class TypeController {
    @Autowired
    TbTypeService tbTypeService;

    /**
     * 添加分类
     * @param tbType
     * @return
     */
    @PostMapping("/addType")
    public Result addType(@RequestBody TbType tbType){
        return tbTypeService.addType(tbType);
    }

    /**
     * 根据id删除分类
     * @param typeId
     * @return
     */
    @DeleteMapping("/deleteByTypeId/{typeId}")
    public Result deleteByTypeId(@PathVariable("typeId") Integer typeId){
        return tbTypeService.deleteByTypeId(typeId);
    }

    /**
     * 获取树形分类列表
     * @return
     */
    @PostMapping("/getTypeTreeList")
    public Result getTypeTreeList(){
        return tbTypeService.getTypeTreeList();
    }

    /**
     * 获取树形分类列表选择下拉框
     * @return
     */
    @PostMapping("/getTypeSelectTree")
    public Result getTypeSelectTree(){
        return tbTypeService.getTypeSelectTree();
    }

    /**
     * 显示或隐藏
     * @param tbType
     * @return
     */
    @PostMapping("/showAndHide")
    public Result showAndHide(@RequestBody TbType tbType){
        return tbTypeService.showAndHide(tbType);
    }

    /**
     * 上传图片
     * @param file
     * @return
     */
    @PostMapping("/loadImage")
    public Result loadImage(@RequestPart("file")MultipartFile file){
        return tbTypeService.loadImage(file);
    }

    /**
     * 修改商品类型信息
     * @param tbType
     * @return
     */
    @PostMapping("/updateType")
    public Result updateType(@RequestBody TbType tbType){
        return tbTypeService.updateType(tbType);
    }


}
